home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-31  |  8.7 KB  |  192 lines  |  [TEXT/MMCC]

  1. /*******************************************************************************
  2. *                                                                              *
  3. *      File fenv.h - PowerPC 601 version,                                      *
  4. *                                                                              *
  5. *      A collection of functions designed to provide access to the floating    *
  6. *      point environment for numerical programming. It is modeled after the    *
  7. *      Numerical C Extensions Group’s requirements ( NCEG / X3J11.1 ).         *
  8. *                                                                              *
  9. *      The file <fenv.h> declares many functions in support of numerical       *
  10. *      programming.  It provides a set of environmental controls similar to    *
  11. *      the ones found in <SANE.h>.  Programs that test flags or run under      *
  12. *      non-default modes must do so under the effect of an enabling            *
  13. *      "fenv_access" pragma.                                                   *
  14. *                                                                              *
  15. *      Copyright © 1992 Apple Computer, Inc.  All rights reserved.             *
  16. *                                                                              *
  17. *      Written by Ali Sazegari, started on October 1992.                       *
  18. *                                                                              *
  19. *      CHANGE LOG (most recent changes first)                                  *
  20. *                                                                              *
  21. *      23 Aug 93      ali      included C++ extern "C" wrappers to make        *
  22. *                              them C++ friendly.                              *
  23. *      08 Apr 93      ali      changed "enums" to "macros" to be more          *
  24. *                              compatible with the FPCE of NCEG.               *
  25. *      05 Feb 93      JPO      Changed function types of feclearexcept,        *
  26. *                              fegetexcept, feraiseexcept, and fesetexcept     *
  27. *                              from int to void to reflect changes in NCEG     *
  28. *                              specification.  Changed definition of           *
  29. *                              FE_DFL_ENV from typedef to #define.  Modified   *
  30. *                              comments describing functionality.              *
  31. *                                                                              *
  32. *******************************************************************************/
  33.  
  34. #ifndef __FENV__
  35. #define __FENV__
  36.  
  37. /*    The typedef fenv_t is a type for representing the entire floating-point
  38.       environment in a single object.                                         */
  39.  
  40. typedef      long int      fenv_t;
  41.  
  42. /*    The typedef fexcept_t is a type for representing the floating-point
  43.       exception flag state collectively.                                      */
  44.  
  45. typedef      long int      fexcept_t;
  46.  
  47. /*    Definitions of floating-point exception macros                          */
  48.  
  49. #define      FE_INEXACT         0x02000000       /*      inexact              */
  50. #define      FE_DIVBYZERO       0x04000000       /*      divide-by-zero       */
  51. #define      FE_UNDERFLOW       0x08000000       /*      underflow            */
  52. #define      FE_OVERFLOW        0x10000000       /*      overflow             */
  53. #define      FE_INVALID         0x20000000       /*      invlalid             */
  54.  
  55. /*    The bitwise OR of all exception macros                                  */
  56.  
  57. #define      FE_ALL_EXCEPT      ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  58.  
  59. /*    Definitions of rounding direction macros                                */
  60.  
  61. #define      FE_TONEAREST       0x00000000 
  62. #define      FE_TOWARDZERO      0x00000001 
  63. #define      FE_UPWARD          0x00000002 
  64. #define      FE_DOWNWARD        0x00000003
  65.  
  66. /*    Definition of pointer to IEEE default environment object                */
  67.  
  68. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  69. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  70.  
  71.  
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75.  
  76. /*******************************************************************************
  77. *     The following functions provide access to the exception flags.  The      *
  78. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  79. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  80. *******************************************************************************/
  81.  
  82. /*    The function "feclearexcept" clears the supported exceptions represented
  83.       by its argument.                                                        */
  84.  
  85. void feclearexcept ( int excepts );
  86.  
  87.  
  88.  
  89. /*    The function "fegetexcept" stores a representation of the exception
  90.       flags indicated by the argument "excepts" through the pointer argument
  91.       "flagp".                                                                */
  92.  
  93. void fegetexcept ( fexcept_t *flagp, int excepts );
  94.  
  95.  
  96.  
  97. /*    The function "feraiseexcept" raises the supported exceptions
  98.       represented by its argument.                                            */
  99.  
  100. void feraiseexcept ( int excepts );
  101.  
  102.  
  103.  
  104. /*    The function "fesetexcept" sets or clears the exception flags indicated
  105.       by the int argument "excepts" according to the representation in the
  106.       object pointed to by the pointer argument "flagp".  The value of
  107.       "*flagp" must have been set by a previous call to "fegetexcept".
  108.       This function does not raise exceptions; it just sets the state of
  109.       the flags.                                                              */
  110.  
  111. void fesetexcept ( const fexcept_t *flagp, int excepts );
  112.  
  113.  
  114.  
  115. /*    The function "fetestexcept" determines which of the specified subset of
  116.       the exception flags are currently set.  The argument "excepts" specifies
  117.       the exception flags to be queried as a bitwise OR of the exception
  118.       macros.  This function returns the bitwise OR of the exception macros
  119.       corresponding to the currently set exceptions included in "excepts".    */
  120.  
  121. int fetestexcept ( int excepts );
  122.  
  123.  
  124.  
  125. /*******************************************************************************
  126. *     The following functions provide control of rounding direction modes.     *
  127. *******************************************************************************/
  128.  
  129. /*    The function "fegetround" returns the value of the rounding direction
  130.       macro which represents the current rounding direction.                  */
  131.  
  132. int fegetround ( void );
  133.  
  134.  
  135.  
  136. /*    The function "fesetround" establishes the rounding direction represented
  137.       by its argument.  It returns nonzero if and only if the argument matches
  138.       a rounding direction macro.  If not, the rounding direction is not
  139.       changed.                                                                */
  140.  
  141. int fesetround ( int round );
  142.  
  143.  
  144.  
  145. /*******************************************************************************
  146. *    The following functions manage the floating-point environment, exception  *
  147. *    flags and dynamic modes, as one entity.                                   *
  148. *******************************************************************************/
  149.  
  150. /*    The function "fegetenv" stores the current floating-point environment
  151.       in the object pointed to by its pointer argument "envp".                */
  152.  
  153. void fegetenv ( fenv_t *envp );
  154.  
  155.  
  156.  
  157. /*    The function "feholdexcept" saves the current environment in the object
  158.       pointed to by its pointer argument "envp", clears the exception flags,
  159.       and clears floating-point exception enables.  This function supersedes
  160.       the SANE function "procentry", but it does not change the current
  161.       rounding direction mode.                                                */
  162.  
  163. int feholdexcept ( fenv_t *envp );
  164.  
  165.  
  166.  
  167. /*    The function "fesetenv" installs the floating-point environment 
  168.       environment represented by the object pointed to by its argument
  169.       "envp".  The value of "*envp" must be set by a call to "fegetenv" or
  170.       "feholdexcept", by an implementation-defined macro of type "fenv_t",
  171.       or by the use of the pointer macro FE_DFL_ENV as the argument.          */
  172.  
  173. void fesetenv ( const fenv_t *envp );
  174.  
  175.  
  176.  
  177. /*    The function "feupdateenv" saves the current exceptions into its
  178.       automatic storage, installs the environment represented through its
  179.       pointer argument "envp", and then re-raises the saved exceptions.
  180.       This function, which supersedes the SANE function "procexit", can be
  181.       used in conjunction with "feholdexcept" to write routines which hide
  182.       spurious exceptions from their callers.                                 */
  183.       
  184. void feupdateenv ( const fenv_t * envp );
  185.  
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189.  
  190.  
  191. #endif
  192.